//package wmmd.mail;

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

// Send a simple, single part, text/plain e-mail
public class Mailer {
    Message msg = null;
    String host, to, from, subject, message = "";
    
    public Mailer(String h) {
        host = h;
    }
    
    public void send() {
        // Create properties, get Session
        Properties props = new Properties();
        
        // If using static Transport.send(),
        // need to specify which host to send it to
        props.put("mail.smtp.host", host);
        //props.put("mail.debug", "true");
        Session session = Session.getInstance(props);
        try {
            // Instantiate a message
            msg = new MimeMessage(session);
            
            //Set message attributes
            msg.setFrom(new InternetAddress(from));
            InternetAddress[] address = {new InternetAddress(to)};
            msg.setRecipients(Message.RecipientType.TO, address);
            msg.setSubject(subject);
            msg.setSentDate(new Date());
            
            // Set message content
            msg.setText(message);
            
            //Send the message
            Transport.send(msg);
        } catch (MessagingException mex) {
            // Prints all nested (chained) exceptions as well
            mex.printStackTrace();
        }
    }
  
    /*--------SETTERS----------*/
    public void setHost(String h) {
        host = h;
    }
    
    public void setSender(String f) {
        from = f;
    }
    
    public void setRecipients(String r) {
        to = r;
    }
    
    public void setSubject(String s) {
        subject = s;
    }
    
    public void setMessage(String m) {
        message = m;
    }
}
